package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.Outreach;
import com.ruoyi.system.service.IOutreachService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * app外外链设置Controller
 *
 * @author ruoyi
 * @date 2024-10-30
 */
@RestController
@RequestMapping("/outreach")
public class OutreachController extends BaseController
{
    @Autowired
    private IOutreachService outreachService;

    /**
     * 查询app外外链设置列表
     */
    @RequiresPermissions("system:outreach:list")
    @GetMapping("/list")
    public TableDataInfo list(Outreach outreach)
    {
        startPage();
        List<Outreach> list = outreachService.selectOutreachList(outreach);
        return getDataTable(list);
    }

    /**
     * 导出app外外链设置列表
     */
    @RequiresPermissions("system:outreach:export")
    @Log(title = "app外外链设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Outreach outreach)
    {
        List<Outreach> list = outreachService.selectOutreachList(outreach);
        ExcelUtil<Outreach> util = new ExcelUtil<Outreach>(Outreach.class);
        util.exportExcel(response, list, "app外外链设置数据");
    }

    /**
     * 获取app外外链设置详细信息
     */
    @RequiresPermissions("system:outreach:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(outreachService.selectOutreachById(id));
    }

    /**
     * 新增app外外链设置
     */
    @RequiresPermissions("system:outreach:add")
    @Log(title = "app外外链设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Outreach outreach)
    {
        return toAjax(outreachService.insertOutreach(outreach));
    }

    /**
     * 修改app外外链设置
     */
    @RequiresPermissions("system:outreach:edit")
    @Log(title = "app外外链设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Outreach outreach)
    {
        return toAjax(outreachService.updateOutreach(outreach));
    }

    /**
     * 删除app外外链设置
     */
    @RequiresPermissions("system:outreach:remove")
    @Log(title = "app外外链设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(outreachService.deleteOutreachByIds(ids));
    }
}
